package demo.genericity;

import java.util.*;

public class GenericityTest2 {
	public static void main(String[] args) {

		TreeSet<Person> ts = new TreeSet<>(new Comparator<Person>() {
			public int compare(Person p1, Person p2) {
				return p2.getName().compareTo(p1.getName());
			}
		});
		ts.add(new Student("sabc--03"));
		ts.add(new Student("sabc--02"));
		ts.add(new Student("sabc--06"));
		ts.add(new Student("sabc--01"));
		ts.add(new Worker("wabc--03"));
		ts.add(new Worker("wabc--02"));
		ts.add(new Worker("wabc--06"));
		ts.add(new Worker("wabc--01"));
		ts.add(new Person("pabc--01"));
		ts.add(new Person("pabc--02"));

		Iterator<Person> it = ts.iterator();

		while (it.hasNext()) {
			System.out.println(it.next().getName());
		}
	}
}

class Person {
	private String name;

	Person(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public String toString() {
		return "person :" + name;
	}
}

class Student extends Person {
	Student(String name) {
		super(name);
	}
}

class Worker extends Person {
	Worker(String name) {
		super(name);
	}
}
